/**
 * Chengzai.com Inc.
 * Copyright (c) 2016-2018 All Rights Reserved.
 */
package com.auxgroup.hr.front.service.hireperson.impl;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.dao.domain.PsCHireOutfT;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dao.domain.PsCHireZcglT;
import com.auxgroup.hr.front.dao.repository.PsCHireOutfTRepository;
import com.auxgroup.hr.front.dao.repository.PsCHireZcglTRepository;
import com.auxgroup.hr.front.service.hireperson.HireOutfTService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 档案细信息服务
 *
 * @author tongqian.ni
 * @version $Id: HireOutfTServiceImpl, v 0.1  2019-01-04.
 */
@Service("hireOutfTService")
public class HireOutfTServiceImpl implements HireOutfTService {
    private static final Logger logger = LoggerFactory.getLogger(HireOutfTServiceImpl.class);

    @Autowired
    private PsCHireOutfTRepository psCHireOutfTRepository;
    @Override
    public PsCHireOutfT getByHire(String hireId) {
        return psCHireOutfTRepository.findOne(hireId);
    }

    @Override
    public PsCHireOutfT save(PsCHireOutfT outf) {
        if(outf.getHrsRowAddDttm() == null){
            outf.setHrsRowAddOprid(outf.getRsHireId());
            outf.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
        }
        outf.setHrsRowUpdOprid(outf.getRsHireId());
        outf.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
        ObjectFieldUtils.handleNullValue(outf);
        return psCHireOutfTRepository.save(outf);
    }
    @Override
    public Boolean delete(String hireId) {
        try {
            psCHireOutfTRepository.delete(hireId);
        } catch (Exception e) {
            logger.error("delete HireZcgl error: hirePrimary={}",hireId,e);
            return false;
        }
        return true;
    }


    @Override
    public List<PsCHireOutfT> getAll(String rsHireId) {
        PsCHireOutfT outf = new PsCHireOutfT();
        outf.setRsHireId(rsHireId);
        return psCHireOutfTRepository.findAll(Example.of(outf),new Sort(Sort.Direction.DESC,"cSeqno"));
    }

}
